<template>
    <a-drawer
    :destroyOnClose="true"
    :title="title"
    placement="right"
    :closable="true"
    :visible="visible"
    :maskClosable="true"
    :width="800"
    @close="close">
        <a-spin :spinning="confirmLoading">
            <div class="table-operator">
                 <a-button shape="round" size="small" type="primary" icon="plus" @click="addPerson()">添加</a-button>
            </div>

            <LTable
                ref="rolePerson"
                size="middle"
                rowKey="keyId"
                :columns="columns"
                :formAttributes="formAttributes"
                axiosUrl="/SysRolePersonController/page"
                :initQuery="initQuery"
                :showPagination="true"
                :showQueryForm="true">
            <span slot="action" slot-scope="text, record">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete({keyId:record.keyId},'/SysRolePersonController/del','rolePerson')">
                    <a>删除</a>
                </a-popconfirm>
            </span>
            </LTable>
            
            <empTransfer ref="empTransfer" @getSelected="getEmpInfo"></empTransfer>

        </a-spin>
    </a-drawer>

</template>

<script>
import LTable from '@/components/lt/LTable'
import pick from 'lodash.pick'
import request from '@/utils/request'
import empTransfer from '@/views/system/emp/empTransfer'
import {SysMixin} from '@/mixins/SysMixin'
import defaultSettings from '@/config/defaultSettings'

export default {
    name:'rolePerson',
    components:{
        empTransfer,LTable
    },
    mixins:[SysMixin],
      props:{
        labelCol:{
            type:Object,
            default:function(){
                return {sm: { span:6 }}
            }
        },
        wrapperCol:{
            type:Object,
            default:function(){
                return {sm: { span: 18 }}
            }
        },
        isShowBootomButton:{
            type:Boolean,
            default:true
        }
      
    },
    data(){
        return{
            initDictCodes:defaultSettings.数据字典.组织下拉树,
            title:'详情',
            visible:false,
            confirmLoading: false,
            model:{},
            defaultSettings,
            localIsShowBootomButton:this.isShowBootomButton,//是否显示提交按钮
             formAttributes:[
                
                {field:'empName',label:'人员姓名',component:'input',condition:'like'},
                {field:'accountNo',label:'账号',component:'input',condition:'like'},
                {field:'empNo',label:'工号',component:'input',condition:'like'},
            ],
            columns:[
                {
                    title: '单位',
                    dataIndex: 'orgNo',
                    customRender:(text)=>{
                        if(!text){
                            return ''
                        }else{
                            return this.dictText(defaultSettings.数据字典.组织下拉树,text)
                           
                        }
                    }
                },
                {
                    title: '姓名',
                    dataIndex: 'empName' 
                },
                {
                    title: '工号',
                    dataIndex: 'empNo' 
                },
                {
                    title: '账号',
                    dataIndex: 'accountNo' 
                },
                 {
                  title: '操作',
                  dataIndex: 'action',
                  width: '100px',
                  scopedSlots: { customRender: 'action' }
                }
                
            ],
            initQuery:[{field:'roleNo',val:'-1'}]


        }
    },
    methods:{
       
        edit (record) {
            
            this.initQuery=[{field:'roleNo',val:record['roleNo']}]
            this.visible = true;
            this.model = Object.assign({}, record);
           
        },
        ok(){
            
        },
        handleCancel(){
            this.visible=false
        },
        close () {
            this.$emit('close');
            this.visible = false;
        },
        /**
         * 表单内容发生变化
         */
        handlerChange(changeItem){
            console.log(changeItem)
           
        },
        addPerson(){
            this.$refs.empTransfer.edit();
        },
        emitClickHandler(field,form){
           
        },
        getForm(){
            return this.$refs.LForm.form
        },
        getEmpInfo(dataSource){
            let that = this
            if(!dataSource || dataSource.length==0){
                that.$message.warning("请先选择人员信息");
                return false;
            }
            that.confirmLoading=true
            dataSource.forEach(function (item) {
                item.roleNo=that.model.roleNo
            })
            let formData={roleNo:that.model.roleNo,empList:dataSource}
            request({url: '/SysRolePersonController/save',method: 'post',data: formData}).then((res)=>{
                if(res.success){
                    that.$refs["rolePerson"].searchQuery()
                    that.$message.success(res.message);
                }else{
                    that.$message.warning(res.message);
                }
            }).finally(() => {
                that.confirmLoading = false;
                
            })
        }
    },
    created(){
        
    },
}
</script>
<style  scoped>
  .drawer-bootom-button {
    position: absolute;
    bottom: 0;
    width: 100%;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: right;
    left: 0;
    background: #fff;
    border-radius: 0 0 2px 2px;
  }

</style>